import { requestClient as request } from '../request';
import { requestClient } from '#/api/request';

import { downloadFileFromBlobPart } from '@vben/utils';

// 获取物料采购计划列表
export function getMaterialBatchBillList2(params: any) {
  return request.post('/admin/MaterialBatchBill/index2', params);
}
// 获取物料采购计划列表
export function getMaterialBatchBillList(params: any) {
  return request.post('/admin/MaterialBatchBill/index', params);
}
/**
 * 导出
 */
export async function exportMaterialBatchBill(params: any) {
  const res = await requestClient.get(
    '/admin/MaterialBatchBill/index2',
    params,
    {
      responseType: 'blob', // 设置响应类型为 blob
      responseReturn: 'raw', // 返回原始响应而不是解析后的数据
    },
  );

  const blob = new Blob([res.data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  });
  downloadFileFromBlobPart({
    source: blob,
    fileName: '生产面辅料逾期情况.xlsx',
  });
}

// 更新批次变更
export function updateBatchOrder(params: any) {
  return request.post(
    '/admin/v2.spuBom/switchChange',
    params,
  );
}

// 获取商品分类选项
export function getCategoryOptions(params: any = {}) {
  return request.post('/admin/goodsCategory/allIndex', params);
}

// 获取时间分类选项
export function getTimeCategoryOptions(params: any = {}) {
  return request.post('/admin/goodsTimeCategory/allIndex', params);
}

// 获取跟单人选项
export function getMerchandiserOptions(params: any = {}) {
  return request.get('/admin/dict/children', {
    key: 'merchUsers',
    limit: 100,
    ...params,
  });
}

// 获取物料类型选项
export function getMaterialTypeOptions(params: any = {}) {
  return request.get('/admin/materialCategory/index', { limit: 30, ...params });
}

// 获取加工厂选项
export function getFactoryOptions(params: any = {}) {
  return request.get('/admin/supply/index', { is_mini: true, ...params });
}
